package com.leoman.dao;

import com.leoman.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * CommentDao
 * Created by 涂奕恒 on 2016/11/23 0023 下午 3:42.
 */
public interface CommentDao extends JpaRepository<Comment, Integer>, JpaSpecificationExecutor<Comment> {

    @Query("select a from Comment a where a.user.id = ?1 and a.sourceId = ?2 and a.sourceType = ?3")
    Comment findOneByParams(Integer userId, Integer sourceId, Integer type);

    @Query("select a from Comment a where a.sourceId = ?1 and a.sourceType = ?2")
    List<Comment> findListBySourceIdAndType(Integer sourceId, Integer type);

    @Query("select a from Comment a where a.isAdmin = 1 and a.sourceId = ?1 and a.sourceType = ?2")
    Comment findOneByParamsAndIsAdmin(Integer sourceId, Integer type);
}